<template>
  <scroll-view scroll-y enable-flex class="video_main" @scrolltolower="scroll">
    <view @click="handleGoVideo(item)" class="video_item" v-for="item in videowp" :key="item.id">
      <image mode="widthFix" :src="item.img"></image>
    </view>
  </scroll-view>
</template>

<script>
export default {
  data() {
    return {
      videowp: [],
      hasMore: true,
    };
  },

  props: {
    urlobj: Object,
  },
  watch: {
    urlobj() {
      this.videowp = [];
      this.getList();
    },
  },
  methods: {
    getList() {
      this.request({
        url: this.urlobj.url,
        data: this.urlobj.params,
      }).then((result) => {
        // console.log(result);
        if (result.res.videowp.length == 0) {
          this.hasMore = false;
          uni.showToast({
            title: "无了,被掏空了",
            icon: "none",
          });

          return;
        }
        this.videowp = [...this.videowp, ...result.res.videowp];
      });
    },
    //分页事件
    scroll() {
      if (this.hasMore) {
        this.urlobj.params.skip += this.urlobj.params.limit;
        this.getList();
      } else {
        uni.showToast({
          title: "无了,被掏空了",
          icon: "none",
        });
      }
    },
    //图片点击事件
    handleGoVideo(item){
      //1. 将数组存到全局共享中
      getApp().globalData.video=item;
      // console.log(getApp().globalData.video);
      //2. 页面跳转
      uni.navigateTo({
        url:"/pages/videoPlay/index"
      })
    }
  },

  mounted() {
    // console.log(this.urlobj);
    this.getList();
  },
};
</script>

<style lang="scss">
.video_main {
  display: flex;
  flex-wrap: wrap;
  height: calc(100vh - 36px);
  .video_item {
    width: 33.33%;
    border: 5rpx solid #fff;
  }
}
</style>